package test.com.john.http;

import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

/**
 * 〈一句话功能简述〉<br/>
 * 〈功能详细描述〉
 *
 * @author jiangguangtao on 2016/4/28.

 */
public class FirstSetup {
    private static final Logger log = LoggerFactory.getLogger(FirstSetup.class);

    @Test
    public void testInit() {
        String url = "http://www.baidu.com/";
        CloseableHttpClient httpClient = HttpClients.createDefault();
        HttpGet httpGet = new HttpGet(url);
        try {
            log.info("get url:{}", url);
            CloseableHttpResponse httpResponse = httpClient.execute(httpGet);
            log.info("请求返回状态：{}", httpResponse.getStatusLine());

            HttpEntity entity = httpResponse.getEntity();
//            EntityUtils.consume(entity);
            String respString = EntityUtils.toString(entity);
            log.info("返回HTML字符串：\n{}", respString);
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
}
